import {createStore} from 'vuex'

const store = createStore({
    state:{//状态存储器
        user:JSON.parse(localStorage.getItem("user")),//存储登录用户信息
        token:localStorage.getItem("token"),//token
        permission:localStorage.getItem("permission")
    },
    mutations:{//自定义函数，用来修改状态存储器中的属性
        loginOut(state){
            state.user = ''
        },
        saveuser(state,user){
            state.user=user
            localStorage.setItem("user",JSON.stringify(user))
        },
        savetoken(state,token){
            state.token=token
            localStorage.setItem("token",token)
        },
        savepermission(state,permission){
            state.permission=permission
            localStorage.setItem("permission",permission)
        },
        cleanInfo(state){
            state.token=""
            state.user=""
            localStorage.setItem("user","")
            localStorage.setItem("token","")
        }
    }
})

//提供外部引用的名称
export default store;